function junmToIosIndex() {
    var u = navigator.userAgent;
    if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
        AndroidWebView.gotoback();
    } else if (u.indexOf('iPhone') > -1) {
        window.webkit.messageHandlers.iOS_goback.postMessage('iOS_goback');
    } else {
        getOther(data);
    }
}
var operationrefundObj = {
    orderid:"",
    posList : [],
    attrParm : " sBarcode='{sBarcode}' returnCount='{nQty}' nItemNo='{nItemNo}' ",
    userId : "",
    sApproveUserId : "",
    sApproveUserName : "",
    sContent : {},
    returnGoodsMap : [],
    bShoppingGuide : true,
    loginName : true,
    init:function () {
        this.orderid = publicObj.getUrlData("oriderid");
        this.getTransantionDetail();
    },
    getTransantionDetail:function () {
        publicObj.showLoad();
        var reqType = "POST";
        var isAsync = true;
        var dataType = "json";
        var reqUrl = ruquireObj.urlPrefix+'OrderService/getdeptmallorderbyid';
        var reqBody={};
        reqBody.sDealCount = this.orderid;
        publicObj.myAjax(this,this.getTDsug,reqUrl,reqBody,reqType,isAsync,dataType);
    },
    getTDsug:function (res,obj) {
        if(res.return.nCode == 0) {
            var resObj = res.response;
            var dataList = resObj.cdoOrderData;
            console.log(resObj);
            obj.bShoppingGuide = resObj.bShoppingGuide;
            obj.userId = dataList.sUserId;
            obj.loginName = resObj.loginName;
            obj.userId = dataList.sUserId;
            var posSaledtl = dataList.posSaledtl;

            var newPosSaledtl = [];

            for (var i=0;i<posSaledtl.length;i++){
                if(posSaledtl[i].nReturnCount < posSaledtl[i].nQty){
                    var saledtObj = posSaledtl[i];
                    saledtObj.nQty = posSaledtl[i].nQty - posSaledtl[i].nReturnCount;
                    newPosSaledtl.push(saledtObj);
                }
            }

            posSaledtl = newPosSaledtl;
            var inHtml = "";
            for (var i=0;i<posSaledtl.length;i++){
                var nQty = posSaledtl[i].nQty;
                var sBarcode = posSaledtl[i].sBarcode;
                var nItemNo = posSaledtl[i].nItemNo;
                var nPluAmount = posSaledtl[i].nPluAmount;
                var nPluDis = posSaledtl[i].nPluDis;
                var nReturnVal = posSaledtl[i].nReturnVal;
                /*var sumPrice = publicObj.reduceNum(nPluAmount,nPluDis);
                sumPrice = publicObj.reduceNum(sumPrice,nReturnVal);
                var price = publicObj.except(sumPrice,nQty);*/
                var price = posSaledtl[i].returnPrice;
                var sGoodsName = posSaledtl[i].sGoodsName;
                var posObj = {};
                posObj.returnCount = nQty;
                posObj.nQty = nQty;
                posObj.sBarcode = sBarcode;
                posObj.nItemNo = nItemNo;
                posObj.price = price;
                posObj.isReturn = true;
                obj.posList.push(posObj);
                if(nQty>1){
                    var Html = obj.getMode();
                    Html = Html.replaceAll("{nQty}",nQty);
                    Html = Html.replaceAll("{sBarcode}",sBarcode);
                    Html = Html.replaceAll("{nItemNo}",nItemNo);
                    Html = Html.replaceAll("{price}",price);
                    Html = Html.replaceAll("{sGoodsName}",sGoodsName);
                    inHtml += Html;
                }else{
                    var Html = obj.getModeX1();
                    Html = Html.replaceAll("{nQty}",nQty);
                    Html = Html.replaceAll("{sBarcode}",sBarcode);
                    Html = Html.replaceAll("{nItemNo}",nItemNo);
                    Html = Html.replaceAll("{price}",price);
                    Html = Html.replaceAll("{sGoodsName}",sGoodsName);
                    inHtml += Html;
                }
            }
            $(".goodslist").html(inHtml);
            obj.bindEvent(obj);
        }
        publicObj.hideLoad();
    },

    bindEvent:function(obj) {
        console.log(obj.posList);
        //勾选 选中事件
        $(".posnoslect").each(function () {
            $(this).bind('click', function (e) {
                $(this).hide();
                var nItemNo = $(this).attr("nItemNo");
                var list = obj.posList;
                for (var i = 0; i < list.length; i++) {
                    var o = list[i];
                    if (o.nItemNo == nItemNo) {
                        obj.posList[i].isReturn = true;
                        break;
                    }
                }
                $(this).siblings().show();
            })
        });
        //勾选  取消选中事件
        $(".posslect").each(function () {
            $(this).bind('click', function (e) {
                $(this).hide();
                var nItemNo = $(this).attr("nItemNo");
                var list = obj.posList;
                for (var i = 0; i < list.length; i++) {
                    var o = list[i];
                    if (o.nItemNo == nItemNo) {
                        obj.posList[i].isReturn = false;
                        break;
                    }
                }
                $(this).siblings().show();
            })
        });

        //编辑数量 按钮事件
        $(".editsnum").each(function () {
            $(this).bind('click', function (e) {
                var nItemNo = $(this).attr("nItemNo");
                console.log(obj.posList);
                var list = obj.posList;
                for (var i = 0; i < list.length; i++) {
                    var o = list[i];
                    if (o.nItemNo == nItemNo) {
                        var oNum = o.returnCount;
                        if(oNum == obj.posList[i].nQty){
                            $(this).siblings(":last").children().last().addClass("upColor");
                        }else{
                            $(this).siblings(":last").children().last().removeClass("upColor");
                        }
                        break;
                    }
                }
                $(this).hide();
                $(this).siblings(":first").hide();
                $(this).siblings(":last").show();
                $(this).next().show();
            })
        });

        //完成 按钮事件
        $(".overedits").each(function () {
            $(this).bind('click', function (e) {
                $(this).hide();
                var nItemNo = $(this).attr("nItemNo");
                var list = obj.posList;
                for (var i = 0; i < list.length; i++) {
                    var o = list[i];
                    if (o.nItemNo == nItemNo) {
                        $(this).siblings(":first").html("×"+o.returnCount);
                        break;
                    }
                }
                $(this).siblings(":first").show();
                $(this).siblings(":last").hide();
                $(this).prev().show();
            })
        });

        //减号事件
        $(".cut").each(function () {
            $(this).bind('click', function (e) {
                var nItemNo = $(this).attr("nItemNo");
                var list = obj.posList;
                for (var i = 0; i < list.length; i++) {
                    var o = list[i];
                    if (o.nItemNo == nItemNo) {
                        var oNum = o.returnCount;
                        $(this).siblings(":last").removeClass("upColor");
                        if(oNum-1 == "1"){
                            $(this).addClass("upColor");
                        }
                        if(oNum == "1"){
                        }else{
                            var num = publicObj.reduceNum(oNum,1);
                            obj.posList[i].returnCount = num;
                            $(this).next().html(num);
                        }
                        break;
                    }
                }
            })
        });

        //加号事件
        $(".add").each(function () {
            $(this).bind('click', function (e) {
                var nItemNo = $(this).attr("nItemNo");
                var list = obj.posList;
                for (var i = 0; i < list.length; i++) {
                    var o = list[i];
                    if (o.nItemNo == nItemNo) {
                        var oNum = o.returnCount;
                        $(this).siblings(":first").removeClass("upColor");
                        if(oNum+1 == obj.posList[i].nQty){
                            $(this).addClass("upColor");
                        }
                        if(oNum == obj.posList[i].nQty){

                        }else{
                            var num = publicObj.plusNum(oNum,1);
                            obj.posList[i].returnCount = num;
                            $(this).prev().html(num);
                        }
                        break;
                    }
                }
            })
        });

        //确定退款
        $(".b_btn").bind("click",function(){
            console.log(obj.posList);
            var reList = obj.posList;
            var reMoney = 0;
            for(var i=0;i<reList.length;i++){
                var o = reList[i]
                if(o.isReturn){
                    var num = o.returnCount;
                    var price = o.price;
                    var rideNum = publicObj.accMul(num,price);
                    console.log(rideNum);
                    reMoney = publicObj.plusNum(reMoney,rideNum);
                    console.log(reMoney);
                }
            }
            console.log(reMoney);
            if(reMoney == 0){
                publicObj.myalert("没有选择需要退货商品！");
                return;
            }
            
            publicObj.showLoad();
            var reqType = "POST";
            var isAsync = true;
            var dataType = "json";
            var contentType = "application/json";
            var reqBody={};
            var reqUrl = ruquireObj.urlPrefix+'returnorderservice/checkreturngoods';
            reqBody.orderId = obj.orderid;
            reqBody.storeId = sessionStorage.getItem("sStoreId");
            reqBody.corpId = sessionStorage.getItem("sCorpId");
            reqBody.userId = obj.userId;
            var returnGoodsMap = [];
            var reList = obj.posList;
            for(var i=0;i<reList.length;i++){
                var reObj = reList[i];
                if(reObj.isReturn){
                    var newReObj = {};
                    newReObj.barcode = reObj.sBarcode;
                    newReObj.nItemNo = reObj.nItemNo;
                    newReObj.returnCount = reObj.returnCount;
                    returnGoodsMap.push(newReObj);
                }
            }
            reqBody.returnGoodsMap = returnGoodsMap;
            //reqBody.sContent = JSON.stringify(sContent);
            console.log("request Body");
            console.log(reqBody);
            publicObj.myAjax(obj,obj.amountMoneyRe,reqUrl,reqBody,reqType,isAsync,dataType,contentType);

        });

        //取消
        $(".left").each(function () {
            $(this).bind('click', function (e) {
                $(".refundbox").hide();
                $(".approvbpx").hide();
                $(".layerbox").hide();
            })
        });

        //金额确定
        $(".amountMoney").bind('click', function (e) {
            if(obj.bShoppingGuide){
                obj.getApprover(obj);
            }else{
                obj.toCommit(obj);
            }
        });

        //审核人选定 提交审批流程
        $(".toCommit").bind('click', function (e) {
            if(obj.sApproveUserId == ""){
                publicObj.myalert("请选择审批人！");
                return ;
            }
            obj.toCommit(obj);
        });
    },


    amountMoneyRe : function (res,obj){
        console.log(res);
        if(res.return.nCode == 0) {
            //reMoney  在返回的 res中获取
            var reMoney = res.response.returnTotalVal;
            $(".money").html("￥"+reMoney);
            $(".refundbox").show();
            $(".approvbpx").hide();
            $(".layerbox").show();
        }else {
            publicObj.myalert(res.return.strText);
        }
        publicObj.hideLoad();

    },


    //提交审批
    toCommit:function (obj){
        publicObj.showLoad();
        var reqType = "POST";
        var isAsync = true;
        var dataType = "json";
        var contentType = "application/json";
        var reqBody={};
        var reqUrl = ruquireObj.urlPrefix+'ApproveService/submitapproves';
        if(obj.bShoppingGuide){
            reqUrl = ruquireObj.urlPrefix+'ApproveService/submitapproves';
            reqBody.sApproveUserId = obj.sApproveUserId;
            reqBody.sApproveUserName = obj.sApproveUserName;
        }else{
            reqUrl = ruquireObj.urlPrefix+'ApproveService/submitandhandleapproves';
            reqBody.sApproveUserId = sessionStorage.getItem("sUserId");
            reqBody.sApproveUserName = obj.loginName;
        }

        reqBody.sDealCount = obj.orderid;
        reqBody.sRemark = "";
        var sContent = {};
        sContent.storeId = sessionStorage.getItem("sStoreId");
        sContent.corpId = sessionStorage.getItem("sCorpId");
        sContent.userId = obj.userId;
        var returnGoodsMap = [];
        var reList = obj.posList;
        for(var i=0;i<reList.length;i++){
            var reObj = reList[i];
            if(reObj.isReturn){
                var newReObj = {};
                newReObj.barcode = reObj.sBarcode;
                newReObj.nItemNo = reObj.nItemNo;
                newReObj.returnCount = reObj.returnCount;
                newReObj.returnValue = publicObj.accMul(reObj.price,reObj.returnCount);
                returnGoodsMap.push(newReObj);
            }
        }
        sContent.returnGoodsMap = returnGoodsMap;
        //reqBody.sContent = JSON.stringify(sContent);
        reqBody.sContent = sContent;
        console.log("request Body");
        console.log(reqBody);
        publicObj.myAjax(this,this.comminRe,reqUrl,reqBody,reqType,isAsync,dataType,contentType);
    },

    //审批回调
    comminRe:function(res,obj){
        publicObj.hideLoad();
        console.log(res);
        if(res.return.nCode == 0) {
            publicObj.myalert("申请成功");
            //var href = './transaction.html?oriderid='+obj.orderid;
            setTimeout("junmToIosIndex()",2000);
        }
        if(res.return.nCode == 1) {
            publicObj.myalert(res.return.strText);
            var href = './transaction.html?oriderid='+obj.orderid;
            setTimeout("location.href = '"+href+"'",2000);
        }
    },

    //查询审核人
    getApprover:function (obj) {
        publicObj.showLoad();
        var reqType = "POST";
        var isAsync = true;
        var dataType = "json";
        var reqUrl = ruquireObj.urlPrefix+'ApproveService/getApproveUsers';
        var reqBody={};
        publicObj.myAjax(obj,this.getApproverRe,reqUrl,reqBody,reqType,isAsync,dataType);
    },
    getApproverRe:function (res,obj) {
        if(res.return.nCode == 0) {
            var resObj = res.response.cdoUserInfos;
            var inHtml ="";
            for(var i=0;i<resObj.length;i++){
                var Html = obj.getApproveUsers();
                Html = Html.replaceAll("{userHeadPicPath}",resObj[i].userHeadPicPath);
                Html = Html.replaceAll("{roleName}",resObj[i].roleName);
                Html = Html.replaceAll("{strName}",resObj[i].strName);
                Html = Html.replaceAll("{lUserId}",resObj[i].lUserId);
                inHtml += Html;
            }
            $(".approverlist").html(inHtml);
            $(".refundbox").hide();
            $(".approvbpx").show();
            console.log(resObj);
            obj.bingEventAppUser(obj);
        }
        publicObj.hideLoad();
    },

    bingEventAppUser:function(obj){
        //审批 勾选选中事件
        $(".appUsernoslect").each(function () {
            $(this).bind('click', function (e) {
                var roleName = $(this).attr("roleName");
                var strName = $(this).attr("strName");
                var lUserId = $(this).attr("lUserId");
                obj.sApproveUserId = lUserId;
                obj.sApproveUserName = roleName+":"+strName;
                $(".appUsernoslect").show();
                $(".appUserslect").hide();
                $(this).hide();
                $(this).siblings().show();
            })
        });
        //审批 勾选  取消选中事件
        $(".appUserslect").each(function () {
            $(this).bind('click', function (e) {
                obj.sApproveUserId = "";
                obj.sApproveUserName = "";
                $(this).hide();
                $(this).siblings().show();
            })
        });
    },

    getMode:function(){
        var html = "<div class=\"goodsbox\">\n" +
            "        <div class=\"num\">×{nQty}</div>\n" +
            "        <div class=\"selectox\" >\n" +
            "            <img src=\"./img/noslect.png\" class=\"noslect posnoslect\" " + this.attrParm +" >\n" +
            "            <img src=\"./img/slect.png\"  class=\"slect posslect activelogo\" " + this.attrParm +" >\n" +
            "        </div>\n" +
            "        <div class=\"goodscode\">{sBarcode}</div>\n" +
            "        <div class=\"subtotal\">￥{price}</div>\n" +
            "        <div class=\"name\">\n" +
            "            {sGoodsName}" +
            "        </div>\n" +
            "        <div class=\"editsnum\" " + this.attrParm +" >\n" +
            "            编辑数量\n" +
            "        </div>\n" +
            "        <div class=\"overedits\" "+ this.attrParm +" >\n" +
            "            完成\n" +
            "        </div>\n" +
            "        <div class=\"numbox\">\n" +
            "            <div class=\"cut\" "+ this.attrParm +" >-</div>\n" +
            "            <div class=\"cnum\">{nQty}</div>\n" +
            "            <div class=\"add\" "+ this.attrParm +" >+</div>\n" +
            "        </div>\n" +
            "    </div>";
        return html;
    },
    getModeX1:function(){
        var html = "<div class=\"goodsbox\">\n" +
            "        <div class=\"num\">×{nQty}</div>\n" +
            "        <div class=\"selectox\" >\n" +
            "            <img src=\"./img/noslect.png\" class=\"noslect posnoslect\" "+this.attrParm+" >\n" +
            "            <img src=\"./img/slect.png\"  class=\"slect posslect activelogo\" "+this.attrParm+" >\n" +
            "        </div>\n" +
            "        <div class=\"goodscode\">{sBarcode}</div>\n" +
            "        <div class=\"subtotal\">￥{price}</div>\n" +
            "        <div class=\"name\">\n" +
            "            {sGoodsName}" +
            "        </div>\n" +
            "    </div>";
        return html;
    },

    getApproveUsers:function () {
        var html = "<div class=\"approver\">\n" +
            "                   <div class=\"hearimgbox\">\n" +
            "                    <img src=\"{userHeadPicPath}\" class=\"hearimg\">\n" +
            "                </div>\n" +
            "                <div class=\"name\">{roleName}:{strName}</div>\n" +
            "                <div class=\"selectox\">\n" +
            "                    <img src=\"./img/noslect.png\"  roleName='{roleName}' strName='{strName}' lUserId='{lUserId}' " +
            "                    class=\"noslect appUsernoslect activelogo\">\n" +
            "                    <img src=\"./img/slect.png\" class=\"slect appUserslect\">\n" +
            "                </div>\n" +
            "            </div>";
        return html;
    }
};
operationrefundObj.init();